package com.jnu.myaccount.data;

import com.jnu.myaccount.function.home.HomeFragment;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;

public class Data implements Serializable,Comparable {
    public String itemName;//本条开销活动名称
    public Double itemCost;//本条开销金额

    public String itemMark;//本条活动的备注
    public Date nowDate;//本条活动的时间
    public int itemPictureID;//本条活动的图片
    public String mDate;//日期
    public String mTime;//时间
    public int year, month, day, hour, minute;
    private long alltime;

    public Data(String name, Double cost, String mark, Date date, int PictureID) {
        this.itemCost = cost;
        this.itemName = name;
        this.itemMark = mark;
        this.nowDate = date;
        getTime();
        this.itemPictureID = PictureID;
        HomeFragment.itemAllMoney += cost;//总资产
        if (cost <= 0)
            HomeFragment.itemAllPaid += cost;//本月支出
        else
            HomeFragment.itemAllEarn += cost;//本月收入
    }

    public String getName() {
        return itemName;
    }


    public double getAllMoney() {
        return HomeFragment.itemAllMoney;
    }

    public double getAllPaid() {
        return HomeFragment.itemAllPaid;
    }

    public double getAllEarn() {
        return HomeFragment.itemAllEarn;
    }

    public String getItemMark() {
        return itemMark;
    }

    public String getItemName() {
        return itemName;
    }

    public int getPictureID() {
        return itemPictureID;
    }

    public double getCost() {
        return itemCost;
    }

    public String getTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(nowDate);                    //放入Date类型数据

        year = calendar.get(calendar.YEAR) - 1900;                    //获取年份
        month = calendar.get(calendar.MONTH) + 1;                    //获取月份
        day = calendar.get(calendar.DATE);                    //获取日

        //calendar.get(Calendar.HOUR);					//时（12小时制）
        hour = calendar.get(calendar.HOUR_OF_DAY);                //时（24小时制）
        minute = calendar.get(calendar.MINUTE);                    //分
        //calendar.get(Calendar.SECOND);					//秒
        DecimalFormat df = new DecimalFormat("00");
        //calendar.get(Calendar.DAY_OF_WEEK);				//一周的第几天
        String time = year + "-" + month + "-" + day + " " + df.format(hour) + ":" + df.format(minute);
        /*SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd  HH:mm");
        String time=dateFormat.format(calendar.getTime());*/
        mDate = year + "-" + month + "-" + day;
        mTime = df.format(hour) + ":" + df.format(minute);
        String allTimeString=String.valueOf(year)+String.valueOf(df.format(month))+String.valueOf(df.format(day))+String.valueOf(df.format(hour))+String.valueOf(df.format(minute));
        alltime=Long.parseLong(allTimeString);

        return time;
    }

    public void setName(String a) {
        this.itemName = a;
    }

    public void setCost(double a) {
        this.itemCost = a;
    }


    @Override
    public int compareTo(Object o) {
        Data s = (Data) o;
        return (int) (this.alltime - s.alltime);
    }

    public String getYearMonth() {
        return month+"-"+day;
    }
}
